﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace _2_11
{
    public partial class Form1 : Form
    {
        private int[] numbers;
        public Form1()
        {
            InitializeComponent();
        }

        private bool IsPrime(int num)
        {
            if (num <= 1)
            {
                return false;
            }
            if (num == 2)
            {
                return true;
            }
            for (int i = 2; i * i <= num; i++)
            {
                if (num % i == 0)
                {
                    return false;
                }
            }
            return true;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int count = int.Parse(textBox1.Text);
            int min = int.Parse(textBox2.Text);
            int max = int.Parse(textBox3.Text);

            numbers = new int[count];
            Random random = new Random();
            string leftText = "";

            for (int i = 0; i < count; i++)
            {
                numbers[i] = random.Next(min, max + 1);
                leftText += numbers[i] + Environment.NewLine;
            }

            textBox4.Text = leftText;
            textBox5.Text = "";
        }

        private void button2_Click(object sender, EventArgs e)
        {
            string rightText = "";

            foreach (int num in numbers)
            {
                if (IsPrime(num))
                {
                    rightText += num + Environment.NewLine;
                }
            }

            textBox5.Text = rightText;
        }
    }
}
